import BaseHttp from './baseHttp'
import store from '../utils/store/index'
import Storage from '../utils/storage'

/**
 * 账户Service
 * @author：丁少华
 * @param：
 * @throws：
 * @time：2018/7/4
 */
class AccountService extends BaseHttp {
  getCode(param) {
    let url = `${this.baseUrl.account}/phone/get_code`
    let res = this.post(url, param)
    return res
  }

  getVerifyCode(param) {
    let url = `${this.baseUrl.account}/phone/get_verify_code_new`
    let res = this.post(url, param)
    return res
  }

  async login(param) {
    let url = `${this.baseUrl.account}/user/login_traffic`
    let res = await this.post(url, param)
    // 登录成功，存入vuex中，全局状态管理&&存入到本地缓存
    if (res.data.status === 'success') {
      store.commit('setToken', res.data.data.token)
      Storage.set('token', res.data.data.token)
      Storage.set('user', res.data.data)
    }
    return res
  }

  async signup(param) {
    let url = `${this.baseUrl.account}/user/signup`
    let res = await this.post(url, param)
    if (res.data.status === 'success') {
      Storage.set('token', res.data.data.token)
    }
    return res
  }

  completeReg(param) {
    let url = `${this.baseUrl.account}/user/edit`
    let res = this.post(url, param)
    return res
  }

  // 获取联系人列表
  getColleague(param) {
    let url = `${this.baseUrl.account}/user_invitation_phone/get_colleague`
    let res = this.post(url, param)
    return res
  }

  // 公司获取已认证企业
  getVerifyCompany(query) {
    let url = `${this.baseUrl.account}/company_relation/get_company_verify`
    let res = this.post(url, query)
    return res
  }

  // 地址管理
  getAdds(param) {
    let url = `${this.baseUrl.account}/address/get`
    let res = this.post(url, param)
    return res
  }

  // 新增地址
  addAdds(param) {
    let url = `${this.baseUrl.account}/address/add`
    let res = this.post(url, param)
    return res
  }

  // 设置默认地址
  setDefaultAdd(param) {
    let url = `${this.baseUrl.account}/address/set_default_address`
    let res = this.post(url, param)
    return res
  }

  // 车辆-获取分组信息
  getCarGroup(param) {
    let url = `${this.baseUrl.account}/relation_group/get_list_group`
    let res = this.post(url, param)
    return res
  }

  // 司机圈-新货源
  driverGuide(param) {
    let url = `${this.baseUrl.line}/stat_c/pass_driver_guide`
    let res = this.post(url, param)
    return res
  }

  //获取指派页面卡片信息
  getCompanyCard(param) {
    let url = `${this.baseUrl.account}/company/get_home_pages`
    let res = this.post(url, param)
    return res
  }
  // 个人设置
  getBase(param) {
    let url = `${this.baseUrl.account}/token/get_base_data`
    let res = this.post(url, param)
    return res
  }
  //获取我的页面卡片信息
  getBusinessCard() {
    let url = `${this.baseUrl.account}/company/get_one`
    let res = this.post(url)
    return res
  }
  //获取我的页面卡片内容信息
  getBsCardDlt(param) {
    let url = `${this.baseUrl.account}/company/get_home_pages`
    let res = this.post(url, param)
    return res
  }

  //获取关系个人主页信息
  getPersonalPage(param) {
    let url = `${this.baseUrl.account}/user/get_personal_homepage`
    let res = this.post(url, param)
    return res
  }

  //获取关系页面客户列表
  getRelationCustomer(param) {
    let url = `${this.baseUrl.account}/user_invitation_phone/get_linkman2`
    let res = this.post(url, param)
    return res
  }

  //保存物流超管设置的提现百分比
  savePerce(param) {
    let url = `${this.baseUrl.account}/percentage_cash/save_percentage`
    let res = this.post(url, param)
    return res
  }

  //物流超管设置的提现百分比
  getPerce(param) {
    let url = `${this.baseUrl.account}/percentage_cash/get_one`
    let res = this.post(url, param)
    return res
  }

  //关系-司机-未分组列表
  getUnDrlist() {
      let url = `${this.baseUrl.account}/user_invitation_phone/get_no_team_driver`
      let res = this.post(url)
      return res
  }

  //关系-司机-自定义列表
  getZdyList(param) {
      let url = `${this.baseUrl.account}/relation_group/get_list_group_user`
      let res = this.post(url)
      return res
  }

  //添加车辆
  addCarDtl(param){
      let url=`${this.baseUrl.account}/user_traffic/traffic_admin_add_user_truck`;
      let res=this.post(url,param);
      return res
  }

  //修改个人信息
  changeUser(param){
      let url=`${this.baseUrl.account}/user_traffic/modify_self`;
      let res=this.post(url,param);
      return res
  }

  //修改企业信息
  changeCompany(param){
      let url=`${this.baseUrl.account}/company/edit`;
      let res=this.post(url,param);
      return res
  }

  // 工厂（js不支持直接定义类属性，ts、java可以）
  // static obj = new AccountService();
  static getInstance() {
    return this.obj
  }
}
AccountService.obj = new AccountService()
export default AccountService.getInstance()
